<template>
  <div class="m-navigation-bar">
    <Item v-for="(item, index) in items" :key="index" :item="item" :active="activeIndex === index"
          @click.native="activeItem(index)"></Item>
  </div>
</template>

<script>
import Item from './item';

export default {
  components: {
    Item
  },
  props: {
    items: {
      type: Array,
      required: true
    },
    value: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      activeIndex: this.value
    };
  },
  methods: {
    activeItem(index) {
      if (this.activeIndex !== index) {
        this.activeIndex = index;
        this.$emit('input', this.activeIndex);
      }
    }
  }
}
</script>

<style lang="scss">
.m-navigation-bar {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-around;
  height: 6rem;
  border-top: 1px solid rgb(242, 242, 242);
}
</style>